package edu.cuc.chap02.lianxi.l3.client;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class TimeClientHandlerL3 extends ChannelInboundHandlerAdapter {
    private ByteBuf byteBuf;
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        String message = "QUERY TIME ORDER";
        byteBuf = Unpooled.buffer(message.getBytes().length);
        byteBuf.writeBytes(message.getBytes());
        ctx.writeAndFlush(byteBuf);
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        ByteBuf byteBuf = (ByteBuf) msg;
        byte[] bytes = new byte[byteBuf.readableBytes()];
        byteBuf.readBytes(bytes);
        String s = new String(bytes);
        System.out.println(s);
    }
}
